package github.sf.fw.utils;

import java.util.Collection;
import java.util.Map;
import java.util.function.Supplier;

public class ArgCheck {
    private ArgCheck() {
    }

    public static void checkEmpty(Object obj, String message) {
        if (obj == null) {
            throw new IllegalArgumentException(message);
        }
        if (obj instanceof String && ((String) obj).isEmpty()) {
            throw new IllegalArgumentException(message);
        }
        if (obj instanceof Collection && ((Collection<?>) obj).isEmpty()) {
            throw new IllegalArgumentException(message);
        }
        if (obj instanceof Map && ((Map<?, ?>) obj).isEmpty()) {
            throw new IllegalArgumentException(message);
        }
    }

    public static void predicate(boolean result, String message) {
        if (result) {
            throw new IllegalArgumentException(message);
        }
    }

    public static void predicate(Supplier<Boolean> func, String message) {
        if (func.get()) {
            throw new IllegalArgumentException(message);
        }
    }

}
